<html>
<head>
<title>logout.py</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.s0 { color: #75715e;}
.s1 { color: #f8f8f2;}
.s2 { color: #66d9ef; font-style: italic;}
.s3 { color: #f92672;}
.s4 { color: #e6db74;}
.s5 { color: #ae81ff;}
.ln { color: #f8f8f2; font-weight: normal; font-style: normal; }
</style>
</head>
<body bgcolor="#272822">
<table CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#606060" >
<tr><td><center>
<font face="Arial, Helvetica" color="#000000">
logout.py</font>
</center></td></tr></table>
<pre><a name="l1"><span class="ln">1    </span></a><span class="s0">#!/usr/bin/python3</span>
<a name="l2"><span class="ln">2    </span></a><span class="s0"># -*- coding: utf-8 -*-</span>
<a name="l3"><span class="ln">3    </span></a><span class="s0">&quot;&quot;&quot; 
<a name="l4"><span class="ln">4    </span></a>@File Name  : logout.py 
<a name="l5"><span class="ln">5    </span></a>@Author     : LeeCQ 
<a name="l6"><span class="ln">6    </span></a>@Date-Time  : 2020/8/29 11:18 
<a name="l7"><span class="ln">7    </span></a>&quot;&quot;&quot;</span>
<a name="l8"><span class="ln">8    </span></a><span class="s2">from </span><span class="s1">common </span><span class="s2">import </span><span class="s3">*</span>
<a name="l9"><span class="ln">9    </span></a><span class="s2">from </span><span class="s1">login </span><span class="s2">import </span><span class="s1">login_easy</span>
<a name="l10"><span class="ln">10   </span></a><span class="s0"># login.py -&gt;</span>
<a name="l11"><span class="ln">11   </span></a><span class="s2">from </span><span class="s1">exc </span><span class="s2">import </span><span class="s1">ElementNotFind, KTMSError</span>
<a name="l12"><span class="ln">12   </span></a><span class="s2">import </span><span class="s1">unittest</span>
<a name="l13"><span class="ln">13   </span></a>
<a name="l14"><span class="ln">14   </span></a>
<a name="l15"><span class="ln">15   </span></a><span class="s2">class </span><span class="s1">TestLogout(unittest.TestCase)</span><span class="s3">:</span>
<a name="l16"><span class="ln">16   </span></a>
<a name="l17"><span class="ln">17   </span></a>    <span class="s2">def </span><span class="s1">setUp(self) -&gt; </span><span class="s2">None</span><span class="s3">:</span>
<a name="l18"><span class="ln">18   </span></a>        <span class="s1">self.driver </span><span class="s3">= </span><span class="s1">login_easy(</span><span class="s4">'test'</span><span class="s1">, </span><span class="s4">'123456'</span><span class="s1">)</span>
<a name="l19"><span class="ln">19   </span></a>
<a name="l20"><span class="ln">20   </span></a>    <span class="s2">def </span><span class="s1">tearDown(self) -&gt; </span><span class="s2">None</span><span class="s3">:</span>
<a name="l21"><span class="ln">21   </span></a>        <span class="s1">self.driver.close()</span>
<a name="l22"><span class="ln">22   </span></a>
<a name="l23"><span class="ln">23   </span></a>    <span class="s2">def </span><span class="s1">test_logout(self)</span><span class="s3">:</span>
<a name="l24"><span class="ln">24   </span></a>        <span class="s1">d </span><span class="s3">= </span><span class="s1">logout(self.driver)</span>
<a name="l25"><span class="ln">25   </span></a>        <span class="s1">self.assertEqual(d.find_element_by_css_selector(</span><span class="s4">'#loginform &gt; fieldset &gt; legend'</span><span class="s1">).text.strip(),</span>
<a name="l26"><span class="ln">26   </span></a>                         <span class="s4">'欢迎登陆K-TMS物流系统'</span><span class="s1">,</span>
<a name="l27"><span class="ln">27   </span></a>                         <span class="s4">'登出成功'</span><span class="s1">)</span>
<a name="l28"><span class="ln">28   </span></a>
<a name="l29"><span class="ln">29   </span></a>
<a name="l30"><span class="ln">30   </span></a><span class="s2">def </span><span class="s1">logout(_driver</span><span class="s3">: </span><span class="s1">BaseWebDriver)</span><span class="s3">:</span>
<a name="l31"><span class="ln">31   </span></a>    <span class="s0">&quot;&quot;&quot;登出 
<a name="l32"><span class="ln">32   </span></a> 
<a name="l33"><span class="ln">33   </span></a>    :param _driver: 已登录的WebDriver对象 
<a name="l34"><span class="ln">34   </span></a>    :return: 0 
<a name="l35"><span class="ln">35   </span></a>    &quot;&quot;&quot;</span>
<a name="l36"><span class="ln">36   </span></a>    <span class="s2">try</span><span class="s3">:</span>
<a name="l37"><span class="ln">37   </span></a>        <span class="s1">_driver.find_element_by_xpath(</span><span class="s4">'//*[@id=&quot;topnav&quot;]/li[4]'</span><span class="s1">).click()</span>
<a name="l38"><span class="ln">38   </span></a>        <span class="s1">_driver.implicitly_wait(</span><span class="s5">8</span><span class="s1">)</span>
<a name="l39"><span class="ln">39   </span></a>        <span class="s1">_driver.find_element_by_class_name(</span><span class="s4">'layui-layer-btn0'</span><span class="s1">).click()</span>
<a name="l40"><span class="ln">40   </span></a>
<a name="l41"><span class="ln">41   </span></a>    <span class="s2">except </span><span class="s1">ElementNotFind</span><span class="s3">:</span>
<a name="l42"><span class="ln">42   </span></a>        <span class="s1">logger.error(</span><span class="s4">'当前对象未登录'</span><span class="s1">)</span>
<a name="l43"><span class="ln">43   </span></a>        <span class="s2">return </span><span class="s1">_driver</span>
<a name="l44"><span class="ln">44   </span></a>
<a name="l45"><span class="ln">45   </span></a>    <span class="s2">try</span><span class="s3">:</span>
<a name="l46"><span class="ln">46   </span></a>        <span class="s1">_driver.implicitly_wait(</span><span class="s5">8</span><span class="s1">)</span>
<a name="l47"><span class="ln">47   </span></a>        <span class="s1">_driver.find_element_by_id(</span><span class="s4">'username'</span><span class="s1">)</span>
<a name="l48"><span class="ln">48   </span></a>        <span class="s1">logger.info(</span><span class="s4">'登出成功'</span><span class="s1">)</span>
<a name="l49"><span class="ln">49   </span></a>        <span class="s2">return </span><span class="s1">_driver</span>
<a name="l50"><span class="ln">50   </span></a>
<a name="l51"><span class="ln">51   </span></a>    <span class="s2">except </span><span class="s1">ElementNotFind</span><span class="s3">:</span>
<a name="l52"><span class="ln">52   </span></a>        <span class="s1">print(</span><span class="s4">&quot;登出是出现了点点小问题。&quot;</span><span class="s1">)</span>
<a name="l53"><span class="ln">53   </span></a>        <span class="s2">raise </span><span class="s1">KTMSError(</span><span class="s4">&quot;登出是出现了点点小问题。&quot;</span><span class="s1">)</span>
<a name="l54"><span class="ln">54   </span></a>
<a name="l55"><span class="ln">55   </span></a>
<a name="l56"><span class="ln">56   </span></a><span class="s2">if </span><span class="s1">__name__ </span><span class="s3">== </span><span class="s4">'__main__'</span><span class="s3">:</span>
<a name="l57"><span class="ln">57   </span></a>    <span class="s2">from </span><span class="s1">login </span><span class="s2">import </span><span class="s1">login_default</span>
<a name="l58"><span class="ln">58   </span></a>
<a name="l59"><span class="ln">59   </span></a>    <span class="s1">logout(login_default())</span>
<a name="l60"><span class="ln">60   </span></a></pre>
</body>
</html>